<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

		<title>购物车页面</title>

		<link href="/static/AmazeUI-2.7.2//AmazeUI-2.7.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
		<link href="/static/frontend/basic/css/demo.css" rel="stylesheet" type="text/css" />
		<link href="/static/frontend/css/cartstyle.css" rel="stylesheet" type="text/css" />
		<link href="/static/frontend/css/optstyle.css" rel="stylesheet" type="text/css" />

		<script type="text/javascript" src="/static/frontend/js/jquery.js"></script>

	</head>

	<body>

		<!--顶部导航条 -->
		{include file="../application/frontend/view/common/pshopcart.html"}

			<!--悬浮搜索框-->

			

			<div class="clear"></div>

			<!--购物车 -->
			<form action="/frontend/order/index" method="post">
			<div class="concent">
				<div id="cartTable">
					<div class="cart-table-th">
						<div class="wp">
							<div class="th th-chk">
								<div id="J_SelectAll1" class="select-all J_SelectAll">

								</div>
							</div>
							<div class="th th-item">
								<div class="td-inner">商品信息</div>
							</div>
							<div class="th th-price">
								<div class="td-inner">单价</div>
							</div>
							<div class="th th-amount">
								<div class="td-inner">数量</div>
							</div>
							<div class="th th-sum">
								<div class="td-inner">金额</div>
							</div>
							<div class="th th-op">
								<div class="td-inner">操作</div>
							</div>
						</div>
					</div>
					<div class="clear"></div>

					<tr class="item-list">
						<div class="bundle  bundle-last ">
							<div class="bundle-hd">
								<div class="bd-promos">
									<div class="bd-has-promo"><span class="bd-has-promo-content">根据您的积分，可享受优惠：{$user_score}</span>&nbsp;&nbsp;</div>
									<div class="act-promo">
										<a href="#" target="_blank"><span class="gt"></span></a>
									</div>
									<span class="list-change theme-login">编辑</span>
								</div>
							</div>
							<div class="clear"></div>
							<div class="bundle-main">
								{foreach $list as $val}
								<ul class="item-content clearfix">
									<li class="td td-chk">
										<div class="cart-checkbox ">
											<input class="c_heck" id="J_CheckBox1" name="items[]" type="checkbox" value="{$val.product_number}">
											<label for="J_CheckBox_170037950254"></label>
										</div>
									</li>
									<li class="td td-item">
										<div class="item-pic">
											<a href="#" target="_blank" class="J_MakePoint" data-point="tbcart.8.12">
												<img src="/static/frontend/img/scenic_img.png" class="itempic J_ItemImg"></a>
										</div>
										<div class="item-info">
											<div class="item-basic-info">
												<a href="#" target="_blank" class="item-title J_MakePoint" data-point="tbcart.8.11">{$val.product_name}</a>
											</div>
										</div>
									</li>
									<li class="td td-info">
										<div class="item-props item-props-can">

											<span class="sku-line">{$val.product_detail}</span>
											
										</div>
									</li>
									<li class="td td-price">
										<div class="item-price price-promo-promo">
											<div class="price-content">
												<!-- <div class="price-line">
													<em class="price-original">78.00</em>
												</div> -->
												<div class="price-line">
													¥<em class="J_Price" tabindex="0" id="pro_price">{$val.product_price}</em>
												</div>
											</div>
										</div>
									</li>
									<li class="td td-amount">
										<div class="amount-wrapper ">
											<div class="item-amount ">
												<div class="sl">
													<input class="min am-btn" name="" type="button" id="btn_reduce" value="-" />
													
													<input class="textBox" name="acount[]" type="text" value="{$val.product_amount}" style="width:30px;" readonly="readonly" />
													<input class="add am-btn" name="" type="button" id="btn_plus" value="+" />
												</div>
											</div>
										</div>
									</li>
									<li class="td td-sum">
										<div class="td-inner">
											¥<em tabindex="0" class="ItemSum">{$val.product_subtotal}</em>
											<input type="hidden" name="totalSum[]" id="totalSum"/>
										</div>
									</li>
									<li class="td td-op">
										<div class="td-inner">
											
											<a href="javascript:;" data-point-url="#" class="delete"> 删除</a>

                 
			                  <input type="hidden" name="shopcart_id" id="shopcart_id" value="{$val.shopcart_id}">
                  
										</div>
									</li>
									
								</ul>
								
								{/foreach}
								
							<input type="hidden" name="productId" id="productId">	
								
													
								
								
								
							</div>
						</div>
					</tr>
					<div class="clear"></div>

					
				</div>
				<div class="clear"></div>

				<div class="float-bar-wrapper">
					<div id="J_SelectAll2" class="select-all J_SelectAll">
						<div class="cart-checkbox">
							<input class="checkAll check" id="J_SelectAllCbx2" name="select-all" value="true" type="checkbox">
							<label for="J_SelectAllCbx2"></label>
						</div>
						<span>全选</span>
					</div>
					<div class="operations">
						<a href="#" hidefocus="true" class="deleteAll" id="deleteAll">删除</a>
						
					</div>
					<div class="float-bar-right">
						<div class="amount-sum">
							<span class="txt" id="selected">已选商品</span>
							<em id="selectedTotal">0</em><span class="txt">件</span>
							<div class="arrow-box">
								<span class="selected-items-arrow"></span>
								<span class="arrow"></span>
							</div>
						</div>
						<div class="price-sum">
							<span class="txt">合计:</span>
							<strong class="price">¥<em id="priceTotal">0.00</em></strong>
							<input type="hidden" id="priceTotal1" name="priceTotal1" >
						</div>
						<div class="btn-area">
							<a href="#" id="J_Go" class="submit-btn submit-btn-disabled" aria-label="请注意如果没有选择宝贝，将无法结算"></a>
								<input type="submit" class="btn-area" style="border:0;background-color: transparent;outline: none;" value="结&nbsp算">
								
						</div>
					</div>

				</div>

				{include file="../application/frontend/view/common/pbottom.html" }

			</div>
		</form>

			<!--操作页面-->

			<div class="theme-popover-mask"></div>

			
		<!--引导 -->
		<div class="navCir">
			<li><a href="home.html"><i class="am-icon-home "></i>首页</a></li>
			<li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
			<li class="active"><a href="shopcart.html"><i class="am-icon-shopping-basket"></i>购物车</a></li>	
			<li><a href="../person/index.html"><i class="am-icon-user"></i>我的</a></li>					
		</div>
	</body>
<script type="text/javascript" src="/static/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
	/*var sum=0;
	$('#btn_plus').click(function(){
		var product_price=$('#price').html();
		var product_num=$('#count').val();
		product_num++;
		console.log(product_price);
		console.log(product_num);
		var total=product_price*product_num;
		console.log(total);
		$('#ItemSum').html(total);
		var a=tr[0].getElementsByTagName('li')[4].getElementsByTagName('input')[1];
		var b=parseFloat(a.value)+1;

   console.log(b);
	});*/

/*	$('#btn_subtract').click(function(){
	var product_price=$('#price').html();
	var product_num=$('#count').val();
	product_num--;
	console.log(product_price);
	console.log(product_num);
	var total=product_price*product_num;
	console.log(total);
	$('#ItemSum').html(total);
	});

	$('#J_CheckBox2').change(function(){
		 $('#J_CheckBox2').val($('#ItemSum').html());
		 var sum1=$('#J_CheckBox2').val();
		if($('#J_CheckBox2').is(':checked'))
		{
			
		sum=parseFloat(sum1);
		alert(sum);
		console.log(sum);
		$('#J_Total').html(sum);
	    }
	    else
	    {
	    	if(sum!=0)
	    	{
	    	sum=sum-sum1;
	    	$('#J_Total').html(sum);}
	    }
		

	});*/
	/*$('#J_CheckBox2').change(function(){
		$('#J_CheckBox2').val($('#ItemSum').html());
		

	});*/
	/*$("[name='items'][checked]").each(function(){
    str+=$(this).val()+",";
     });*/


</script>
<script type="text/javascript">
	/*var table = document.getElementById('cartTable'); // 购物车表格
    var selectInputs = document.getElementsByClassName('check'); // 所有勾选框
    //console.log(selectInputs);
    var checkAllInputs = document.getElementsByClassName('check-all') 
    //console.log(checkAllInputs); // 全选框
    //
   var tr=document.getElementsByClassName('item-content');
   // var tr = table.children[0].rows; //行
    console.log(tr);

    var selectedTotal = document.getElementById('selectedTotal'); //已选商品数目容器
    console.log(selectedTotal);
    var priceTotal = document.getElementById('priceTotal'); //总计
    console.log(priceTotal);
    var deleteAll = document.getElementById('deleteAll'); // 删除全部按钮
    console.log(deleteAll);
    //var selectedViewList = document.getElementById('selectedViewList'); //浮层已选商品列表容器s
    var selected = document.getElementById('selected'); //已选商品
    console.log(selected);
    //var foot = document.getElementById('foot');
    var productTotal = document.getElementById('pro_price').innerHTML;
    console.log(productTotal);

    var c=parseFloat(tr[1].getElementsByClassName('J_Price')[0].innerHTML);
   
    console.log(c);
    var a=parseInt(tr[0].getElementsByTagName('input')[2].value);
    console.log(a);
    var e=tr[1].getElementsByTagName('input')[0];
    console.log(e);*/



    
    
   
		/*var a=tr[0].getElementsByTagName('li')[4].getElementsByTagName('input')[1];
		var b=parseFloat(a.value)+1;*/


    // 更新总数和总价格，已选浮层
   

</script>
<script type="text/javascript">

var shopcart_id=new Array();
var checkbox=$('.c_heck');
var checkAll=$('.checkAll');
var itemContent=$('.item-content');

var reduce=$('.min'),
plus=$('.add'),
all_sum=$('.textBox');

function totalMoney(){
	var total_money=0,
	    total_count=0;

    checkbox.each(function(){
    	
    		if($(this).is(':checked'))
    		{
    			
    			var goods=parseFloat($(this).parents('.item-content').find('.ItemSum').html());//单品小计
    			var num=parseInt($(this).parents('.item-content').find('.textBox').val());//单品数量
    			
    			total_money+=goods;
    			total_count+=num;
    			$('#selectedTotal').html(total_count);

    		}

    	});
   
    	
    	$('#priceTotal').html(parseFloat(total_money));
    	$('#priceTotal1').val(total_money);
    	
    	
    }
   

	reduce.click(function()
	{
		var inputval=$(this).next('input'),
		
		count=parseInt(inputval.val())-1,
		
		priceTotalObj=$(this).parents('.item-content').find('.ItemSum'),
		
		price=$(this).parents('.item-content').find('.J_Price').html(),
		priceTotal=count*parseFloat(price);
		inputval.val(count);
		if(inputval.val()<=0)
	    {
	      $(this).attr("disabled",true); 
	      priceTotalObj.html('0');
	    }
	    else
	    {
	    	priceTotalObj.html(priceTotal);
	    }
		
		var id=$(this).parents('.item-content').find('.c_heck').val();
		console.log(id);
		totalMoney();
			$.ajax({
				type:"post",
				url:"/frontend/shopcart/ajax",
				data:{id:id,priceTotal:priceTotal,count:count},
				dataType:"json",
				success:function(ret){
					console.log(ret);
					console.log(id);
				    }

	     });
	});
	plus.click(function()
	{
		var inputval=$(this).prev('input'),
		count=parseInt(inputval.val())+1,
		priceTotalObj=$(this).parents('.item-content').find('.ItemSum'),//小计
		
		price=$(this).parents('.item-content').find('.J_Price').html(),//单价
		priceTotal=count*parseFloat(price);
		inputval.val(count);
		if(inputval.val()>0)
       {
	      $(this).parents('.item-amount').find('#btn_reduce').attr("disabled",false);
	      priceTotalObj.html(priceTotal);
       }

		totalMoney();
		var id=$(this).parents('.item-content').find('.c_heck').val();
			$.ajax({
				type:"post",
				url:"/frontend/shopcart/ajax",
				data:{id:id,priceTotal:priceTotal,count:count},
				dataType:"json",
				success:function(ret){
					console.log(ret);
					console.log(id);
				    }

	     });
		
	});


var selected=document.getElementsByClassName("c_heck");
var c_box=document.getElementsByName("shopcart_id");
console.log(c_box);
var allCheck=document.getElementsByClassName("checkAll")[0];
var ids = '';
   checkbox.each(function(){
   	$(this).click(function(){
   		var len=checkbox.length;
   		
   		var num=0;
   		for(var i=0;i<len;i++)
   		{
   			if (selected[i].checked==true) 
   			{
                num++;
                console.log(c_box[i].value);

                 //ids += ',' + $(this).val();
                 shopcart_id[i]=c_box[i].value;
                 console.log(shopcart_id);
                
               /* var id=$(this).parents('.item-content').find('#shopcart_id').val();
                console.log();
                shopcart_id=id;
                console.log(shopcart_id);
                $('#productId').val(shopcart_id);	
                console.log($('#productId').val());*/
                
                
            }
            else
            {
            	shopcart_id[i]='';
            }
            if(num==len)
            {
            	allCheck.checked=true;
            }
            else
            {
            	allCheck.checked=false;
            }
            
   		}

   			$('#productId').val(shopcart_id);	
            console.log($('#productId').val());
   			totalMoney();
   		
   	});
   	

   });


    checkAll.click(function(){
   	var item_content=itemContent.find('input[type="checkbox"]');
   	if($(this).is(':checked'))
   	{
   		item_content.prop("checked",true);
   	}
   	else
   	{
   		item_content.prop("checked",false);
   	}
        totalMoney();
   });



$('.delete').click(function(){
	var item_content = $(this).parents('.item-content');
	var id=$(this).parents('.td-inner').find('#shopcart_id').val();
	console.log(id);
	var conf = '确定删除此商品吗？';
	if(confirm(conf)==true)
	{
	 item_content.remove();
	 $.ajax({
				type:"post",
				url:"/frontend/shopcart/delete",
				data:{id:id},
				dataType:"json",
				success:function(ret){
					
					console.log(ret);
					alert("删除成功");
				    }

	     });
    }

})


/*$('.insert').click(function(){
	var a=document.getElementById('priceTotal').innerHTML;
	var b=$('#priceTotal').html();
    console.log(b);
	$.ajax({
		type:"post",
		url:"/frontend/order/ajax",
		data:{test:b},
		dataType:"json",
		success:function(ret){
			console.log(ret);
		}

	});

})*/
	
</script>
</html>